/**
 * 
 */
package evolution.view;

import javax.swing.SwingWorker;

import evolution.Evolution;
import evolution.mlp.MLP;
import evolution.tutors.Tutor;

/**
 * @author camille
 * 
 */
public class RevoWorker extends SwingWorker<Void, Void> {

	public static final String PROGRESS = "progress";
	public static final String DATA = "data";
	public static final String INFO = "info";
	public static final String MLP = "mlp";

	private MLP mlp;
	private Tutor tutor;
	private Evolution evolution;

	private MLP fittest;

	public RevoWorker(MLP mlp, Tutor tutor, Evolution evolution) {

		this.mlp = mlp;

		this.tutor = tutor;

		this.evolution = evolution;
		this.evolution.setWorker(this);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.swing.SwingWorker#doInBackground()
	 */
	@Override
	protected Void doInBackground() throws Exception {
		fittest = evolution.saes(mlp, tutor);
		return null;
	}

	@Override
	protected void done() {
		if (fittest != null) {
			firePropertyChange(INFO, null, "Fitness : " + tutor.fitness(fittest));
			firePropertyChange(INFO, null, "Results : " + tutor.results(fittest));
			firePropertyChange(MLP, null, fittest);
		}

		setProgress(100);
	}

}
